%compute repayment policy
function b_0 = fun_buyback(b,A,del,cub_spl_v,cub_spl_x )

[Delta_max,fv2]= fsolve(@(d) del-d.*max(0,min(fnval(cub_spl_x,[b-d;A]),1)),del*0.1);
[b_0, ff]      = fmincon(@(b_new) -(fnval(cub_spl_v,[b_new;A])  -  fnval(cub_spl_x,[b_new;A]).*(b-b_new)),b,[],[],[],[],max(0,b-Delta_max),b);
